package com.cskaoyan.jdbc;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/06/01 11:23
 *
 * @author ciggar
 */
public class DeleteDemo {

    static String url = "jdbc:mysql://localhost:3306/41th?useSSL=false&characterEncoding=utf8";
    static String username = "root";
    static String password = "123456";

    public static void main(String[] args) throws SQLException {

        // 1. 注册驱动  // 传入的是驱动包里面的Driver接口的实现
        DriverManager.registerDriver(new Driver());

        // 2. 建立连接 JDBC4Connection
        Connection connection = DriverManager.getConnection(url,username,password);

        // 3. 获取Statement对象  StatementImpl
        Statement statement = connection.createStatement();

        // 4. 发送SQL语句
        // 执行查询语句
        // statement.executeQuery();

        // 执行增删改语句
        int affectedRows = statement.executeUpdate("delete from city where id = 1003");


             // 5. 解析结果集
        System.out.println("affectedRows:" + affectedRows);

        //6. 断开连接
        statement.close();
        connection.close();



    }
}
